package edu.sctu.practice.class02.zhaozhongjun.assign3.a1.a2;

/**
 * Created by zhao on 2015/11/5.
 */
public class Main {

    public static void main(String[] args) {
        ComparableCircle circle1 = new ComparableCircle(9);
        ComparableCircle circle2 = new ComparableCircle(3);
        Comparable circle = Max.max(circle1, circle2);
        System.out.println("最大的圆的半径是" + ((Circle) circle).getRadius());
        System.out.println(circle);
        ComparableCylinder cylinder1 = new ComparableCylinder(6, 2);
        ComparableCylinder cylinder2 = new ComparableCylinder(4, 5);
        Comparable cylinder = Max.max(cylinder1, cylinder2);
        System.out.println();
        System.out.println("圆柱1的体积是" + cylinder1.findVolume());
        System.out.println("圆柱2的体积是" + cylinder2.findVolume());
        System.out.println("最大的圆柱的\n半径是 " + ((Cylinder) cylinder).getRadius() + "\n长是： " + ((Cylinder) cylinder).getLength() + "\n体积是： " + ((Cylinder) cylinder).findVolume());
        System.out.println(cylinder);
    }
}

class ComparableCircle extends Circle implements Comparable {
    public ComparableCircle(double r) {
        super(r);
    }

    public int compareTo(Object o) {
        if (getRadius() > ((Circle) o).getRadius()) return 1;
        else if (getRadius() < ((Circle) o).getRadius()) return -1;
        else return 0;
    }
}

class ComparableCylinder extends Cylinder implements Comparable {
    ComparableCylinder(double r, double l) {
        super(r, l);
    }

    public int compareTo(Object o) {
        if (findVolume() > ((Cylinder) o).findVolume()) return 1;
        else if (findVolume() < ((Cylinder) o).findVolume()) return -1;
        else return 0;
    }
}

